home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbpcopy / jmtree.bas < prev    next >
BASIC Source File  |  1998-10-01  |  18KB  |  397 lines

  1. Attribute VB_Name = "DirectoryTreeSubs"
  2. Option Explicit
  3.  
  4.     
  5. ' Brought to you by:
  6. '  Brad Martinez
  7. '  btmtz@aol.com
  8. '  http://members.aol.com/btmtz/vb
  9.  
  10. '///////////////////////////////////////////////////////////////////////////////////////////////////////////
  11.  
  12. ' A little info...
  13. ' Objects in the shellÆs namespace are assigned item identifiers and item
  14. ' identifier lists. An item identifier uniquely identifies an item within its parent
  15. ' folder. An item identifier list uniquely identifies an item within the shellÆs
  16. ' namespace by tracing a path to the item from the desktop.
  17.  
  18. '///////////////////////////////////////////////////////////////////////////////////////////////////////////
  19.  
  20. ' An item identifier is defined by the variable-length SHITEMID structure.
  21. ' The first two bytes of this structure specify its size, and the format of
  22. ' the remaining bytes depends on the parent folder, or more precisely
  23. ' on the software that implements the parent folderÆs IShellFolder interface.
  24. ' Except for the first two bytes, item identifiers are not strictly defined, and
  25. ' applications should make no assumptions about their format.
  26.     Type SHITEMID   ' mkid
  27.         cb As Long       ' Size of the ID (including cb itself)
  28.         abID() As Byte  ' The item ID (variable length)
  29.     End Type
  30.  
  31. ' The ITEMIDLIST structure defines an element in an item identifier list
  32. ' (the only member of this structure is an SHITEMID structure). An item
  33. ' identifier list consists of one or more consecutive ITEMIDLIST structures
  34. ' packed on byte boundaries, followed by a 16-bit zero value. An application
  35. ' can walk a list of item identifiers by examining the size specified in each
  36. ' SHITEMID structure and stopping when it finds a size of zero. A pointer
  37. ' to an item identifier list, is sometimes called a PIDL (pronounced piddle)
  38.     Type ITEMIDLIST   ' idl
  39.         mkid As SHITEMID
  40.     End Type
  41.  
  42. ' Converts an item identifier list to a file system path.
  43. ' Returns TRUE if successful or FALSE if an error occurs, for example,
  44. ' if the location specified by the pidl parameter is not part of the file system.
  45.     Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pIdl As Long, ByVal pszPath As String) As Long
  46.  
  47. ' Retrieves the location of a special (system) folder.
  48. ' Returns NOERROR if successful or an OLE-defined error result otherwise.
  49.     Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pIdl As ITEMIDLIST) As Long
  50.  
  51. ' SHGetSpecialFolderLocation successful rtn val
  52.     Public Const NOERROR = 0
  53.  
  54. ' SHGetSpecialFolderLocation nFolder params:
  55. ' Most folder locations are stored in:
  56. ' [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders]
  57. ' Value specifying the types of folders to be listed in the dialog box as well as other options.
  58. ' This member can be 0 or one of the following values:
  59.  
  60. ' Windows desktop, virtual folder at the root of the name space.
  61.     Public Const CSIDL_DESKTOP = &H0
  62.  
  63. ' File system directory that contains the user's program groups
  64. ' (which are also file system directories).
  65.     Public Const CSIDL_PROGRAMS = &H2
  66.  
  67. ' Control Panel, virtual folder containing icons for the control panel applications.
  68.     Public Const CSIDL_CONTROLS = &H3
  69.  
  70. ' Printers folder, virtual folder containing installed printers.
  71.     Public Const CSIDL_PRINTERS = &H4
  72.  
  73. ' File system directory that serves as a common respository for documents.
  74.     Public Const CSIDL_PERSONAL = &H5   ' (Documents folder)
  75.  
  76. ' File system directory that contains the user's favorite Internet Explorer URLs.
  77.     Public Const CSIDL_FAVORITES = &H6
  78.  
  79. ' File system directory that corresponds to the user's Startup program group.
  80.     Public Const CSIDL_STARTUP = &H7
  81.  
  82. ' File system directory that contains the user's most recently used documents.
  83.     Public Const CSIDL_RECENT = &H8   ' (Recent folder)
  84.  
  85. ' File system directory that contains Send To menu items.
  86.     Public Const CSIDL_SENDTO = &H9
  87.  
  88. ' Recycle bin, file system directory containing file objects in the user's recycle bin.
  89. ' The location of this directory is not in the registry; it is marked with the hidden and
  90. ' system attributes to prevent the user from moving or deleting it.
  91.     Public Const CSIDL_BITBUCKET = &HA
  92.  
  93. ' File system directory containing Start menu items.
  94.     Public Const CSIDL_STARTMENU = &HB
  95.  
  96. ' File system directory used to physically store file objects on the desktop
  97. ' (not to be confused with the desktop folder itself).
  98.     Public Const CSIDL_DESKTOPDIRECTORY = &H10
  99.  
  100. ' My Computer, virtual folder containing everything on the local computer: storage
  101. ' devices, printers, and Control Panel. The folder may also contain mapped network drives.
  102.     Public Const CSIDL_DRIVES = &H11
  103.  
  104. ' Network Neighborhood, virtual folder representing the top level of the network hierarchy.
  105.     Public Const CSIDL_NETWORK = &H12
  106.  
  107. ' File system directory containing objects that appear in the network neighborhood.
  108.     Public Const CSIDL_NETHOOD = &H13
  109.  
  110. ' Virtual folder containing fonts.
  111.     Public Const CSIDL_FONTS = &H14
  112.  
  113. ' File system directory that serves as a common repository for document templates.
  114.     Public Const CSIDL_TEMPLATES = &H15   ' (ShellNew folder)
  115.  
  116. '========================================================
  117.  
  118. ' Frees memory allocated by SHBrowseForFolder()
  119.     Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
  120.  
  121. ' Displays a dialog box that enables the user to select a shell folder.
  122. ' Returns a pointer to an item identifier list that specifies the location
  123. ' of the selected folder relative to the root of the name space. If the user
  124. ' chooses the Cancel button in the dialog box, the return value is NULL.
  125.     Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long ' ITEMIDLIST
  126.  
  127. ' Contains parameters for the the SHBrowseForFolder function and receives
  128. ' information about the folder selected by the user.
  129.     Public Type BROWSEINFO   ' bi
  130.         
  131.         ' Handle of the owner window for the dialog box.
  132.         hOwner As Long
  133.         
  134.         ' Pointer to an item identifier list (an ITEMIDLIST structure) specifying the location
  135.         ' of the "root" folder to browse from. Only the specified folder and its subfolders
  136.         ' appear in the dialog box. This member can be NULL, and in that case, the
  137.         ' name space root (the desktop folder) is used.
  138.         pidlRoot As Long
  139.         
  140.         ' Pointer to a buffer that receives the display name of the folder selected by the
  141.         ' user. The size of this buffer is assumed to be MAX_PATH bytes.
  142.         pszDisplayName As String
  143.         
  144.         ' Pointer to a null-terminated string that is displayed above the tree view control
  145.         ' in the dialog box. This string can be used to specify instructions to the user.
  146.         lpszTitle As String
  147.         
  148.         ' Value specifying the types of folders to be listed in the dialog box as well as
  149.         ' other options. This member can include zero or more of the following values below.
  150.         ulFlags As Long
  151.         
  152.         ' Address an application-defined function that the dialog box calls when events
  153.         ' occur. For more information, see the description of the BrowseCallbackProc
  154.         ' function. This member can be NULL.
  155.         lpfn As Long
  156.         
  157.         ' Application-defined value that the dialog box passes to the callback function
  158.         ' (if one is specified).
  159.         lParam As Long
  160.         
  161.         ' Variable that receives the image associated with the selected folder. The image
  162.         ' is specified as an index to the system image list.
  163.         iImage As Long
  164.     
  165.     End Type
  166.  
  167. ' BROWSEINFO ulFlags values:
  168. ' Value specifying the types of folders to be listed in the dialog box as well as
  169. ' other options. This member can include zero or more of the following values:
  170.  
  171. ' Only returns file system directories. If the user selects folders
  172. ' that are not part of the file system, the OK button is